package max.ta.data.plot;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import max.ta.data.access.CSVDataLoader;
import max.ta.data.access.StockeQuoteCSVLoader;
import max.ta.data.entity.StockQuote;
import max.ta.data.plot.data.MathPoint;

import org.apache.log4j.Logger;

public class TimeSeriesChartPlotterTest {

    private static final Logger logger = Logger.getLogger(TimeSeriesChartPlotterTest.class);

    private static final File CSV_FILE = new File("data/IBM.csv");


    public static void main(final String[] args) throws IOException {
	final TimeSeriesChartPlotter demo = new TimeSeriesChartPlotter("IBM Stock");
	List<MathPoint<Date, Double>> points = loadData();
	demo.plot("Close", points);
    }

    // /http://www.informit.com/guides/content.aspx?g=java&seqNum=75

    private static List<MathPoint<Date, Double>> loadData() throws IOException {
	List<MathPoint<Date, Double>> points = new ArrayList<MathPoint<Date, Double>>();
	CSVDataLoader<StockQuote> loader = new StockeQuoteCSVLoader();
	List<StockQuote> quotes = loader.load(CSV_FILE);
	for (StockQuote q : quotes) {
	    logger.info(q);
	    MathPoint<Date, Double> p = new MathPoint<Date, Double>(q.getDate(), q.getClose());
	    points.add(p);
	}
	return points;
    }
}
